package com.example.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.domain.ChatUser;
import com.example.mapper.ChatUserMapper;
import com.example.service.ChatUserService;
import com.example.utils.R;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.stereotype.Service;

/**
* @author 93879
* @description 针对表【chat_user(聊天用户表)】的数据库操作Service实现
* @createDate 2024-01-29 19:36:07
*/
@Service
public class ChatUserServiceImpl extends MPJBaseServiceImpl<ChatUserMapper, ChatUser>
    implements ChatUserService{

    @Override
    public R login(String username, String password) {
        ChatUser chatUser = baseMapper.selectOne(new LambdaQueryWrapper<ChatUser>()
                .eq(ChatUser::getUsername, username));
        // 判断用户是否注册
        if(ObjectUtil.isEmpty(chatUser)){
            return R.error("用户未注册");
        }
        // 判断密码是否正确
        if(chatUser.getPassword().equals(password)){
            return R.ok("登陆成功").setData(chatUser);
        }
        return R.error("密码错误");
    }
}




